package com.haoxuewa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoxuewa.dao.AdminDao;
import com.haoxuewa.entity.Admin;
import com.haoxuewa.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminDao, Admin> implements AdminService {


    private final AdminDao adminDao;

    @Autowired
    public AdminServiceImpl(AdminDao adminDao) {
        this.adminDao = adminDao;
    }


    @Override
    public Admin adminLogin(String name, String password) {
        return adminDao.selectOne(new QueryWrapper<Admin>().eq("name", name)
                .eq("password", password));
    }


    @Override
    public Admin selectAdminsByName(String name) {
        return adminDao.selectOne(new QueryWrapper<Admin>().eq("name", name));
    }

    @Override
    public Boolean addAdmin(String name, String password) {
        Admin admin = new Admin();
        admin.setName(name);
        admin.setPassword(password);
        return adminDao.insert(admin) == 1;
    }

    @Override
    public Boolean deleteAdmin(String name) {
        return adminDao.delete(new QueryWrapper<Admin>().eq("name", name)) == 1;
    }

}
